/**
 * 
 */
package uk.ac.manchester.tewpl.iceiface.client.model;

import java.util.HashSet;
import java.util.Set;

import com.extjs.gxt.ui.client.data.BaseModelData;
import com.google.gwt.user.client.rpc.IsSerializable;

/**
 * @author roland
 * 
 */
public class KBUserModel extends BaseModelData implements IsSerializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2216338156254370672L;
	public static final String ID = "id";
	public static final String SURNAME = "surname";
	public static final String FIRSTNAME = "firstname";
	public static final String EMAIL = "email";
	public static final String PASSWORD = "password";
	public static final String COMMUNITIES = "communities";

	public KBUserModel() {
		set(COMMUNITIES, new HashSet<KBCommunityModel>());
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.explorium.model.KBUser#getCommunities()
	 */
	public Set<KBCommunityModel> getCommunities() {
		// TODO Auto-generated method stub
		return get(COMMUNITIES);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.explorium.model.KBUser#getEmail()
	 */
	public String getEmail() {
		// TODO Auto-generated method stub
		return get(EMAIL);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.explorium.model.KBUser#getFirstname()
	 */
	public String getFirstname() {
		return get(FIRSTNAME);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.explorium.model.KBUser#getId()
	 */
	public Long getId() {
		return get(ID);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.explorium.model.KBUser#getPassword()
	 */
	public String getPassword() {
		return get(PASSWORD);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.explorium.model.KBUser#getSurname()
	 */
	public String getSurname() {
		return get(SURNAME);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.explorium.model.KBUser#joinCommunity(org.explorium.model.KBCommunity)
	 */
	public void joinCommunity(KBCommunityModel community) {
		getCommunities().add(community);
		community.addMember(this);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.explorium.model.KBUser#leaveCommunity(org.explorium.model.KBCommunity
	 * )
	 */
	public void leaveCommunity(KBCommunityModel community) {
		getCommunities().remove(community);
		community.removeMember(this);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.explorium.model.KBUser#setCommunities(java.util.Set)
	 */
	public void setCommunities(Set<KBCommunityModel> communities) {
		set(COMMUNITIES, communities);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.explorium.model.KBUser#setEmail(java.lang.String)
	 */
	public void setEmail(String email) {
		set(EMAIL, email);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.explorium.model.KBUser#setFirstname(java.lang.String)
	 */
	public void setFirstname(String firstname) {
		set(FIRSTNAME, firstname);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.explorium.model.KBUser#setId(java.lang.Long)
	 */
	public void setId(Long id) {
		set(ID, id);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.explorium.model.KBUser#setPassword(java.lang.String)
	 */
	public void setPassword(String password) {
		set(PASSWORD, password);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.explorium.model.KBUser#setSurname(java.lang.String)
	 */
	public void setSurname(String surname) {
		set(SURNAME, surname);
	}

	
	@Override
	public boolean equals(Object obj) {
		if (obj instanceof KBUserModel) {
			KBUserModel o = (KBUserModel) obj;
			return getId().equals(o.getId());
		}
		return false;
	}

}
